<template>
	<view @click="copy" class="copy">
		<text><slot></slot></text>
		<text v-if="showIcon" class="iconfont icon-copy fz12 ml5 green" title="点击复制"></text>
	</view>
</template>

<script>
	export default {
		name: 'copy',
		data() {
			return {
				
			};
		},
		props: {
			text: {
				type: String,
				default: ''
			},
			showIcon:{
				default : false 
			}
		},
		methods: {
			copy : function(e){
				if (!this.text) {
					uni.showToast({
						title: '无可复制的数据',
						icon : 'none'
					});
					return false ;
				}
				uni.setClipboardData({
					data: this.text ,
					success : function(e){
						uni.showToast({
							title: '复制成功',
							icon : 'success'
						});	
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
.copy{
	cursor: pointer;
	transition: 0.4s;
	&:hover{
		color: #5d83f7;
	}
}
</style>
